package com.timmy.test1.view;

import android.content.Context;
import android.icu.text.UFormat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.timmy.test1.App;
import com.timmy.test1.R;

/**
 * Created by timmy on 2020/5/6.
 */

public class JKeyBoardView extends RelativeLayout {
    public View all_key_layout;

    public boolean isAltDown;

    public boolean isCtrlDown;

    public boolean isEditMode;

    public boolean isShiftDown;

    private KeyView keyAlt;

    private KeyView keyCtrl;

    private KeyView keyShiftLeft;

    View.OnTouchListener keyTouch = new View.OnTouchListener() {
        @Override
        public boolean onTouch(final View v, MotionEvent param1MotionEvent) {
            final int[] local = new int[2];
            if (!JKeyBoardView.this.isClickable())
                return false;
            KeyView keyView = (KeyView) v;
            int i = keyView.getScanCode();
            int j = param1MotionEvent.getAction();
            if (j == 0) {
                int[] arrayOfInt = new int[2];
                v.getLocationOnScreen(arrayOfInt);
                if (i != -1 && i != -2 && i != -3) {
//                    if (JKeyBoardView.this.tv_key_toast == null)
//                        if (JiActivity.tv_key_toast != null) {
//                            JKeyBoardView.access$002(JKeyBoardView.this, JiActivity.tv_key_toast);
//                        } else if (AnalogButtonActivity.tv_key_toast != null) {
//                            JKeyBoardView.access$002(JKeyBoardView.this, AnalogButtonActivity.tv_key_toast);
//                        }
                    if (JKeyBoardView.this.tv_key_toast != null) {
                        JKeyBoardView.this.tv_key_toast.setText(keyView.getText());
                        JKeyBoardView.this.tv_key_toast.post(new Runnable() {
                            @Override
                            public void run() {
                                FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) JKeyBoardView.this.tv_key_toast.getLayoutParams();
                                int j = v.getLeft() + v.getWidth() / 2 - JKeyBoardView.this.tv_key_toast.getWidth() / 2 + AutoSizeUtil.getAutoWidth(v.getContext(), 8);
                                int i = j;
                                if (j < 0) {
                                    i = 0;
                                }
                                j = i;
                                if (JKeyBoardView.this.tv_key_toast.getWidth() + i >= App.SCREEN_HEIGHT) {
                                    j = App.SCREEN_HEIGHT - JKeyBoardView.this.tv_key_toast.getWidth();
                                }

                                StringBuilder stringBuilder = new StringBuilder();
                                stringBuilder.append("??--");
                                stringBuilder.append(local[0]);
                                stringBuilder.append(" ");
                                stringBuilder.append(local[1]);
                                stringBuilder.append(" ");
                                stringBuilder.append(v.getLeft());
                                stringBuilder.append(" ");
                                stringBuilder.append(v.getTop());
//                            Timber.e(stringBuilder.toString(), new Object[0]);

                                layoutParams.leftMargin = j;
                                layoutParams.topMargin = (int) (local[1] - v.getHeight() * 2.5D);
                                JKeyBoardView.this.tv_key_toast.setLayoutParams((ViewGroup.LayoutParams) layoutParams);
                                JKeyBoardView.this.tv_key_toast.setVisibility(View.VISIBLE);
                            }
                        });

                    }
                }
                if (!JKeyBoardView.this.isEditMode) {
                    if (i == 42 || i == 54) {
//                        if (JKeyBoardView.this.keyShiftLeft == null)
//                            JKeyBoardView.access$102(JKeyBoardView.this, keyView);
                        if (JKeyBoardView.this.isShiftDown) {
                            JKeyBoardView.this.isShiftDown = false;
                            return true;
                        }
                        JKeyBoardView.this.isShiftDown = true;
                        JKeyBoardView.this.doShiftChange(true);

                    } else if (i == 29) {
//                        if (JKeyBoardView.this.keyCtrl == null) {
//                            JKeyBoardView.access$202(JKeyBoardView.this, keyView);
//                        }
                        if (JKeyBoardView.this.isCtrlDown) {
                            JKeyBoardView.this.isCtrlDown = false;
                            return true;
                        }
                        JKeyBoardView.this.isCtrlDown = true;
                    } else if (i == 56) {
                        if (JKeyBoardView.this.keyAlt == null) {
//                            null JKeyBoardView.access$302(JKeyBoardView.this, keyView);
                        }
                        if (JKeyBoardView.this.isAltDown) {
                            JKeyBoardView.this.isAltDown = false;
                            return true;
                        }
                        JKeyBoardView.this.isAltDown = true;
                    }
                }
                if (i == -1) {
//                    Timber.e("按下隐藏", new Object[0]);
                } else if (i == -2) {
                    v.setBackgroundResource(R.mipmap.key_local_type_in_change_press);
                } else if (i == -3) {
                    v.setBackgroundResource(R.mipmap.key_type_switch_press);
                } else {
                    v.setBackgroundResource(R.drawable.shape_key_press);
                }
                if (JKeyBoardView.this.mJKeyListener != null) {
                    JKeyBoardView.this.mJKeyListener.onJKeyDown(keyView);
                }
                return true;
            }
            if (j == 1 || j == 3) {
                if (i != -1 && i != -2 && i != -3 && JKeyBoardView.this.tv_key_toast != null) {
                    JKeyBoardView.this.tv_key_toast.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            if (JKeyBoardView.this.tv_key_toast != null) {
                                JKeyBoardView.this.tv_key_toast.setVisibility(View.INVISIBLE);
                            }
                        }
                    }, 100L);
                }
                if (!JKeyBoardView.this.isEditMode) {
                    if (i == 42 || i == 54) {
                        if (JKeyBoardView.this.isShiftDown) {
                            return true;
                        }
                        JKeyBoardView.this.doShiftChange(false);
                    } else if (i == 29) {
                        if (JKeyBoardView.this.isCtrlDown) {
                            return true;
                        }
                    } else if (i == 56) {
                        if (JKeyBoardView.this.isAltDown) {
                            return true;
                        }
                    } else if (i == -1) {
                        if (JKeyBoardView.this.isShiftDown) {
                            JKeyBoardView.this.isShiftDown = false;
                            JKeyBoardView.this.keyTouch.onTouch((View) JKeyBoardView.this.keyShiftLeft, (MotionEvent) param1MotionEvent);
                        }
                        if (JKeyBoardView.this.isAltDown) {
                            JKeyBoardView.this.isAltDown = false;
                            JKeyBoardView.this.keyTouch.onTouch((View) JKeyBoardView.this.keyAlt, (MotionEvent) param1MotionEvent);
                        }
                        if (JKeyBoardView.this.isCtrlDown) {
                            JKeyBoardView.this.isCtrlDown = false;
                            JKeyBoardView.this.keyTouch.onTouch((View) JKeyBoardView.this.keyCtrl, (MotionEvent) param1MotionEvent);
                        }
                    }
                }
                if (i != -1) {
                    if (i == -2) {
                        v.setBackgroundResource(R.mipmap.key_local_type_in_change_normal);
                    } else if (i == -3) {
                        v.setBackgroundResource(R.mipmap.key_type_switch_normal);
                    } else {
                        v.setBackgroundResource(R.drawable.shape_key);
                    }
                }
                if (JKeyBoardView.this.mJKeyListener != null) {
                    JKeyBoardView.this.mJKeyListener.onJKeyUp(keyView);
                }
                return true;
            }
            return true;
        }
    };

    private KeyView leftShift;

    public LinearLayout ll_row1;

    public LinearLayout ll_row2;

    public LinearLayout ll_row3;

    public LinearLayout ll_row4;

    public LinearLayout ll_row5;

    public LinearLayout ll_row6;

    private boolean mClickable = true;

    private Context mContext;

    public JKeyListener mJKeyListener;

    private View mView;

    private KeyView rightShift;

    private KeyView tv_key_alt;

    public KeyView tv_key_change;

    private KeyView tv_key_ctrl;

    private KeyView tv_key_left_shift;

    private TextView tv_key_toast;

    public JKeyBoardView(Context paramContext) {
        super(paramContext);
        this.mContext = paramContext;
        init();
    }

    public JKeyBoardView(Context paramContext, AttributeSet paramAttributeSet) {
        super(paramContext, paramAttributeSet);
        this.mContext = paramContext;
        init();
    }

    public JKeyBoardView(Context paramContext, AttributeSet paramAttributeSet, int paramInt) {
        super(paramContext, paramAttributeSet, paramInt);
        this.mContext = paramContext;
        init();
    }

    private void init() {
        int j;
        View view = LayoutInflater.from(this.mContext).inflate(R.layout.layout_keyboard, (ViewGroup) this);
        this.mView = view;
        this.tv_key_change = (KeyView) view.findViewById(R.id.tv_key_change);
        this.all_key_layout = this.mView.findViewById(R.id.all_key_layout);
        this.ll_row1 = (LinearLayout) this.mView.findViewById(R.id.ll_key_row1);
        this.ll_row2 = (LinearLayout) this.mView.findViewById(R.id.ll_key_row2);
        this.ll_row3 = (LinearLayout) this.mView.findViewById(R.id.ll_key_row3);
        this.ll_row4 = (LinearLayout) this.mView.findViewById(R.id.ll_key_row4);
        this.ll_row5 = (LinearLayout) this.mView.findViewById(R.id.ll_key_row5);
        this.ll_row6 = (LinearLayout) this.mView.findViewById(R.id.ll_key_row6);
        byte b = 0;
        int i;
        for (i = 0; i < this.ll_row1.getChildCount(); i++)
            this.ll_row1.getChildAt(i).setOnTouchListener(this.keyTouch);
        for (i = 0; i < this.ll_row2.getChildCount(); i++)
            this.ll_row2.getChildAt(i).setOnTouchListener(this.keyTouch);
        for (i = 0; i < this.ll_row3.getChildCount(); i++)
            this.ll_row3.getChildAt(i).setOnTouchListener(this.keyTouch);
        for (i = 0; i < this.ll_row4.getChildCount(); i++)
            this.ll_row4.getChildAt(i).setOnTouchListener(this.keyTouch);
        i = 0;
        while (true) {
            j = b;
            if (i < this.ll_row5.getChildCount()) {
                this.ll_row5.getChildAt(i).setOnTouchListener(this.keyTouch);
                if (this.ll_row5.getChildAt(i).getId() == R.id.tv_key_left_shift) {
                    this.leftShift = (KeyView) this.ll_row5.getChildAt(i);
                } else if (this.ll_row5.getChildAt(i).getId() == R.id.tv_key_right_shift) {
                    this.rightShift = (KeyView) this.ll_row5.getChildAt(i);
                }
                i++;
                continue;
            }
            break;
        }
        while (j < this.ll_row6.getChildCount()) {
            this.ll_row6.getChildAt(j).setOnTouchListener(this.keyTouch);
            j++;
        }
        this.tv_key_left_shift = (KeyView) this.mView.findViewById(R.id.tv_key_left_shift);
        this.tv_key_alt = (KeyView) this.mView.findViewById(R.id.tv_key_alt);
        this.tv_key_ctrl = (KeyView) this.mView.findViewById(R.id.tv_key_ctrl);
    }

    public void doShiftChange(boolean paramBoolean) {
        if (paramBoolean) {
            if (!this.isEditMode) {
                this.rightShift.setBackgroundResource(R.drawable.shape_key_press);
                this.leftShift.setBackgroundResource(R.drawable.shape_key_press);
            }
            ((KeyView) findViewById(R.id.tv_key_grave)).setText("~");
            ((KeyView) findViewById(R.id.tv_key_1)).setText("!");
            ((KeyView) findViewById(R.id.tv_key_2)).setText("@");
            ((KeyView) findViewById(R.id.tv_key_3)).setText("#");
            ((KeyView) findViewById(R.id.tv_key_4)).setText("$");
            ((KeyView) findViewById(R.id.tv_key_5)).setText("%");
            ((KeyView) findViewById(R.id.tv_key_6)).setText("^");
            ((KeyView) findViewById(R.id.tv_key_7)).setText("&");
            ((KeyView) findViewById(R.id.tv_key_8)).setText("*");
            ((KeyView) findViewById(R.id.tv_key_9)).setText("(");
            ((KeyView) findViewById(R.id.tv_key_0)).setText(")");
            ((KeyView) findViewById(R.id.tv_key_minus)).setText("_");
            ((KeyView) findViewById(R.id.tv_key_equals)).setText("+");
            ((KeyView) findViewById(R.id.tv_key_q)).setText("Q");
            ((KeyView) findViewById(R.id.tv_key_w)).setText("W");
            ((KeyView) findViewById(R.id.tv_key_e)).setText("E");
            ((KeyView) findViewById(R.id.tv_key_r)).setText("R");
            ((KeyView) findViewById(R.id.tv_key_t)).setText("T");
            ((KeyView) findViewById(R.id.tv_key_y)).setText("Y");
            ((KeyView) findViewById(R.id.tv_key_u)).setText("U");
            ((KeyView) findViewById(R.id.tv_key_i)).setText("I");
            ((KeyView) findViewById(R.id.tv_key_o)).setText("O");
            ((KeyView) findViewById(R.id.tv_key_p)).setText("P");
            ((KeyView) findViewById(R.id.tv_key_left_bracket)).setText("{");
            ((KeyView) findViewById(R.id.tv_key_right_bracket)).setText("}");
            ((KeyView) findViewById(R.id.tv_key_backslash)).setText("|");
            ((KeyView) findViewById(R.id.tv_key_a)).setText("A");
            ((KeyView) findViewById(R.id.tv_key_s)).setText("S");
            ((KeyView) findViewById(R.id.tv_key_d)).setText("D");
            ((KeyView) findViewById(R.id.tv_key_f)).setText("F");
            ((KeyView) findViewById(R.id.tv_key_g)).setText("G");
            ((KeyView) findViewById(R.id.tv_key_h)).setText("H");
            ((KeyView) findViewById(R.id.tv_key_j)).setText("J");
            ((KeyView) findViewById(R.id.tv_key_k)).setText("K");
            ((KeyView) findViewById(R.id.tv_key_l)).setText("L");
            ((KeyView) findViewById(R.id.tv_key_semicolon)).setText(":");
            ((KeyView) findViewById(R.id.tv_key_yin)).setText("\"");
            ((KeyView) findViewById(R.id.tv_key_z)).setText("Z");
            ((KeyView) findViewById(R.id.tv_key_x)).setText("X");
            ((KeyView) findViewById(R.id.tv_key_c)).setText("C");
            ((KeyView) findViewById(R.id.tv_key_v)).setText("V");
            ((KeyView) findViewById(R.id.tv_key_b)).setText("B");
            ((KeyView) findViewById(R.id.tv_key_n)).setText("N");
            ((KeyView) findViewById(R.id.tv_key_m)).setText("M");
            ((KeyView) findViewById(R.id.tv_key_comma)).setText("<");
            ((KeyView) findViewById(R.id.tv_key_period)).setText(">");
            ((KeyView) findViewById(R.id.tv_key_slash)).setText("?");
            return;
        }
        if (!this.isEditMode) {
            this.rightShift.setBackgroundResource(R.drawable.shape_key);
            this.leftShift.setBackgroundResource(R.drawable.shape_key);
        }
        ((KeyView) findViewById(R.id.tv_key_grave)).setText("`");
        ((KeyView) findViewById(R.id.tv_key_1)).setText("1");
        ((KeyView) findViewById(R.id.tv_key_2)).setText("2");
        ((KeyView) findViewById(R.id.tv_key_3)).setText("3");
        ((KeyView) findViewById(R.id.tv_key_4)).setText("4");
        ((KeyView) findViewById(R.id.tv_key_5)).setText("5");
        ((KeyView) findViewById(R.id.tv_key_6)).setText("6");
        ((KeyView) findViewById(R.id.tv_key_7)).setText("7");
        ((KeyView) findViewById(R.id.tv_key_8)).setText("8");
        ((KeyView) findViewById(R.id.tv_key_9)).setText("9");
        ((KeyView) findViewById(R.id.tv_key_0)).setText("0");
        ((KeyView) findViewById(R.id.tv_key_minus)).setText("-");
        ((KeyView) findViewById(R.id.tv_key_equals)).setText("=");
        ((KeyView) findViewById(R.id.tv_key_q)).setText("q");
        ((KeyView) findViewById(R.id.tv_key_w)).setText("w");
        ((KeyView) findViewById(R.id.tv_key_e)).setText("e");
        ((KeyView) findViewById(R.id.tv_key_r)).setText("r");
        ((KeyView) findViewById(R.id.tv_key_t)).setText("t");
        ((KeyView) findViewById(R.id.tv_key_y)).setText("y");
        ((KeyView) findViewById(R.id.tv_key_u)).setText("u");
        ((KeyView) findViewById(R.id.tv_key_i)).setText("i");
        ((KeyView) findViewById(R.id.tv_key_o)).setText("o");
        ((KeyView) findViewById(R.id.tv_key_p)).setText("p");
        ((KeyView) findViewById(R.id.tv_key_left_bracket)).setText("[");
        ((KeyView) findViewById(R.id.tv_key_right_bracket)).setText("]");
        ((KeyView) findViewById(R.id.tv_key_backslash)).setText("\\");
        ((KeyView) findViewById(R.id.tv_key_a)).setText("a");
        ((KeyView) findViewById(R.id.tv_key_s)).setText("s");
        ((KeyView) findViewById(R.id.tv_key_d)).setText("d");
        ((KeyView) findViewById(R.id.tv_key_f)).setText("f");
        ((KeyView) findViewById(R.id.tv_key_g)).setText("g");
        ((KeyView) findViewById(R.id.tv_key_h)).setText("h");
        ((KeyView) findViewById(R.id.tv_key_j)).setText("j");
        ((KeyView) findViewById(R.id.tv_key_k)).setText("k");
        ((KeyView) findViewById(R.id.tv_key_l)).setText("l");
        ((KeyView) findViewById(R.id.tv_key_semicolon)).setText(";");
        ((KeyView) findViewById(R.id.tv_key_yin)).setText("'");
        ((KeyView) findViewById(R.id.tv_key_z)).setText("z");
        ((KeyView) findViewById(R.id.tv_key_x)).setText("x");
        ((KeyView) findViewById(R.id.tv_key_c)).setText("c");
        ((KeyView) findViewById(R.id.tv_key_v)).setText("v");
        ((KeyView) findViewById(R.id.tv_key_b)).setText("b");
        ((KeyView) findViewById(R.id.tv_key_n)).setText("n");
        ((KeyView) findViewById(R.id.tv_key_m)).setText("m");
        ((KeyView) findViewById(R.id.tv_key_comma)).setText(",");
        ((KeyView) findViewById(R.id.tv_key_period)).setText(".");
        ((KeyView) findViewById(R.id.tv_key_slash)).setText("/");
    }

    public void initDown() {
        if (this.isShiftDown) {
            doShiftChange(false);
            this.tv_key_left_shift.setBackgroundResource(R.drawable.shape_key);
            this.isShiftDown = false;
        }
        if (this.isAltDown) {
            this.tv_key_alt.setBackgroundResource(R.drawable.shape_key);
            this.isAltDown = false;
        }
        if (this.isCtrlDown) {
            this.tv_key_ctrl.setBackgroundResource(R.drawable.shape_key);
            this.isCtrlDown = false;
        }
    }

    @Override
    public boolean isClickable() {
        return this.mClickable;
    }

    @Override
    public boolean onTouchEvent(MotionEvent paramMotionEvent) {
        return true;
    }

    @Override
    public void setClickable(boolean paramBoolean) {
        super.setClickable(paramBoolean);
        this.mClickable = paramBoolean;
    }

    public void setJKeyListener(JKeyListener paramJKeyListener) {
        this.mJKeyListener = paramJKeyListener;
    }

    public static interface JKeyListener {
        void onJKeyDown(KeyView param1KeyView);

        void onJKeyUp(KeyView param1KeyView);
    }
}


/* Location:              C:\Users\timmy\Documents\Tencent Files\825125501\FileRecv\0xcfd85000-dex2jar.jar!\cn\ji_cloud\android\views\JKeyBoardView.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */